package nl.marcoslot.apps.alm;

import java.awt.Container;
import java.awt.EventQueue;
import java.awt.Toolkit;
import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JTextField;
import javax.swing.WindowConstants;
import nl.marcoslot.lib.gui.layout.alm.ArithmeticLayoutManager;

/**
 *
 * @author Marco Slot
 */
public class ALMTest2 extends JFrame {
    
    /** Creates new form ALMTest */
    public ALMTest2() {
        init();
    }
    
    public void init() {
        Container panel = getContentPane();
        panel.setLayout(new ArithmeticLayoutManager());
        
        JLabel title = new JLabel("<html><h1>ArithmeticLayoutManager</h1></html>");
        panel.add(title,
                "x = 0.5 * parent.width - 0.5 * this.width;"+
                "y = 20;                                   ");
        
        JLabel nameLabel = new JLabel("Name");
        panel.add(nameLabel, 
                "name   = label;              " +
                "left   = 15;                 " +
                "top    = 90;                 " +
                "width  = 0.2 * parent.width; ");
        
        JTextField nameField = new JTextField("");
        panel.add(nameField, 
                "name   = nameField;          " +
                "left   = label.rRight + 20;  " +
                "top    = label.top;          " +
                "right  = 20;                 ");
        
        String[] fields = new String[] {"Address",
                                        "Postal code",
                                        "Country",
                                        "Phone"};
        
        for(int i = 0; i < fields.length; i++) {
            JLabel     label = new JLabel(fields[i]);
            JTextField field = new JTextField();
            
            panel.add(label,
                    "top  = label.top + 40; " +
                    "left = label.left;     " +
                    "right= label.right;    " +
                    "name = label;          ");  /* note: override label*/
            
            panel.add(field,
                    "top  = label.top;      " +
                    "left = nameField.left; " +
                    "right= nameField.right;");
        }
        
        JButton submitButton = new JButton("Submit");
        panel.add(submitButton, 
                "top    = label.top + 40; " +
                "right  = 20;             ");
        
        setSize(400, 400);
        setTitle("ALM Sample 2");
        setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    }
    
    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        EventQueue.invokeLater(new Runnable() {
            public void run() {
                new ALMTest2().setVisible(true);
            }
        });
    }
    
}
